﻿using System;
using System.Diagnostics.Contracts;
using EPiServer.Core;

namespace OpenWaves.EPiServer.CustomProperties
{
    [ContractClass(typeof(StringPropertyContract<>))]
    public abstract class StringProperty<T> : StringPropertyBase<T>
    {
        public override PropertyData ParseToObject(string value)
        {
            return this.CreateInstance(this.DeserializeValueWithCheck(value));
        }

        public override PropertyDataType Type
        {
            get { return PropertyDataType.String; }
        }

        protected abstract StringProperty<T> CreateInstance(T value);
    }

    [ContractClassFor(typeof(StringProperty<>))]
    abstract class StringPropertyContract<T> : StringProperty<T>
    {
        protected override StringProperty<T> CreateInstance(T value)
        {
            Contract.Ensures(Contract.Result<StringProperty<T>>() != null);
            throw new NotImplementedException();
        }
    }
}